using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using XLua;

public class Singlrtonlua
{
    private static Singlrtonlua _instance;
    public static Singlrtonlua Instance
    {
        get
        {
            if (_instance == null)
            {
                _instance = new Singlrtonlua();
            }
            return _instance;
        }
    }
    LuaEnv Lua;
    private Singlrtonlua()
    {
        Lua = new LuaEnv();
        Lua.AddLoader(ProjectLoader);
    }

    private byte[] ProjectLoader(ref string filepath)
    {
        string path = Application.dataPath + "LuaScripts/" + filepath + ".lua";
        path = path.Replace("Assets", "");
        if (File.Exists(path))
        {
            return File.ReadAllBytes(path);
        }
        else
        {
            return null;
        }
    }
    public void Free()
    {
        if (Lua != null)
        {
            Lua.Dispose();
            _instance = null;
        }
    }
}
